﻿Imports DevExpress.XtraEditors

Public Class ClsUcnTabPage
    Inherits DevExpress.XtraTab.XtraTabPage
    'represents tabcontrol for tabs

#Region "Attributes"
#Region "Private attributes"
    Private MbReadyForUse As Boolean = False 'indicates proper initialization of usercontrol
    Private MoTabControl As UcnTabControl = Nothing 'parent UcnTabControl 
    '------------------------------------------------------------------------------------------------------------------------
    'USED ON kkMainTab and kkClassDiagramTab TAB
    Private WithEvents MoUcnDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = Nothing 'UcnDiagramCanvasAdvanced usercontrol in tab

    'USED ON kkVersionComparisonTab TAB
    Private WithEvents MoSplitContainerControl As SplitContainerControl = Nothing 'split control which 2x UcnDiagramCanvasBase canvases are in
    Private WithEvents MoLeftCanvasAdvanced As UcnDiagramCanvasAdvanced = Nothing 'left canvas in version comparison
    Private WithEvents MoRightCanvasAdvanced As UcnDiagramCanvasAdvanced = Nothing 'right canvas in version comparison
    '------------------------------------------------------------------------------------------------------------------------

    Private MeTypeOfTab As GeTypeOfTab = GeTypeOfTab.kkNone 'type of tab
#End Region
#End Region
#Region "Constructors & Init"
    Sub New(ByVal IeTypeOfTab As GeTypeOfTab, ByVal IoTabControl As UcnTabControl)
        MyBase.New()
        MoTabControl = IoTabControl
        MeTypeOfTab = IeTypeOfTab
        Text = "???"
        SuperTip = Nothing

        '**********************************************************************
        InitControl()
        '**********************************************************************
    End Sub
    'setting usercontrol settings before its using
    Private Function InitControl() As GeActionResult
        SetReadyForUse(False) 'disabling usercontrol
        Try
            Me.Dock = DockStyle.Fill
            SetReadyForUse(True) 'enabling usercontrol
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'initialization of controls
    Public Function Init() As GeActionResult

    End Function
#End Region
#Region "Properties"
#Region "Public properties"
    Public ReadOnly Property ReadyForUse() As Boolean
        Get
            Return MbReadyForUse
        End Get
    End Property
    Public ReadOnly Property TypeOfTab() As GeTypeOfTab
        Get
            Return MeTypeOfTab
        End Get
    End Property
    Public ReadOnly Property ucnDiagramCanvasAdvanced(Optional ByVal IeSideOfCanvas As GeSideOfCanvas = GeSideOfCanvas.kkNone) As UcnDiagramCanvasAdvanced
        Get
            Select Case TypeOfTab
                Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                    Return MoUcnDiagramCanvasAdvanced
                Case Else
                    Select Case IeSideOfCanvas
                        Case GeSideOfCanvas.kkLeft
                            Return LeftCanvasAdvanced
                        Case GeSideOfCanvas.kkRight
                            Return RightCanvasAdvanced
                        Case Else
                            LogEvent("Nevrateny ucnDiagramCanvasAdvanced z tabu! Ziadny kkNone neexistuje!", , )
                    End Select
                    LogEvent("Nevrateny ucnDiagramCanvasAdvanced z tabu!", , )
                    Return Nothing
            End Select
        End Get
    End Property
    Public Property SplitContainerControl() As SplitContainerControl
        Get
            Return MoSplitContainerControl
        End Get
        Set(ByVal IoValue As SplitContainerControl)
            MoSplitContainerControl = IoValue
        End Set
    End Property
    Public Property LeftCanvasAdvanced() As UcnDiagramCanvasAdvanced
        Get
            Return MoLeftCanvasAdvanced
        End Get
        Set(ByVal IoValue As UcnDiagramCanvasAdvanced)
            MoLeftCanvasAdvanced = IoValue
        End Set
    End Property
    Public Property RightCanvasAdvanced() As UcnDiagramCanvasAdvanced
        Get
            Return MoRightCanvasAdvanced
        End Get
        Set(ByVal IoValue As UcnDiagramCanvasAdvanced)
            MoRightCanvasAdvanced = IoValue
        End Set
    End Property
#End Region
#End Region
#Region "Functions"
    'add a UcnDiagramCanvasAdvanced to tab's Controls collectionand set MoUcnDiagramCanvasAdvanced property
    Public Function AddCanvasToControlsCollection(ByVal IoUcnDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced) As GeActionResult
        Try
            Controls.Add(IoUcnDiagramCanvasAdvanced)
            MoUcnDiagramCanvasAdvanced = IoUcnDiagramCanvasAdvanced

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'add a SplitContainerControl to tab's Controls collectionand set MoSplitContainerControl property
    Public Function AddSplitControlToControlsCollection(ByVal IoSplitContainerControl As SplitContainerControl) As GeActionResult
        Try
            Controls.Add(IoSplitContainerControl)
            MoSplitContainerControl = IoSplitContainerControl

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Subs"
    'sets MbReadyForUse attribute and sets Enable property of usercontrol
    Private Sub SetReadyForUse(ByVal IbValue As Boolean)
        MbReadyForUse = IbValue
        Me.Enabled = IbValue 'enabling usercontrol
    End Sub
#End Region

    '#######################################
    'execute function
    Public Function Execute(ByRef OoAction As ClsAction) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk
            '---------------------------------------------
            'ACTION BEFORE ACTION
            '---------------------------------------------
            '---------------------------------------------
            'ACTION
            '---------------------------------------------
            Select Case OoAction.Action
                Case GeAction.kkInitTab
                    'initialization of Tab for the first usage
                    Select Case MeTypeOfTab
                        Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                            OoAction.SetData(GeSideOfCanvas.kkNone, "SIDEOFCANVAS")
                            OoAction.SetData(MoUcnDiagramCanvasAdvanced, "UCNDIAGRAMCANVASADVANCED")
                            LeResult = MoUcnDiagramCanvasAdvanced.Execute(OoAction)
                        Case GeTypeOfTab.kkVersionComparisonTab
                            OoAction.SetData(GeSideOfCanvas.kkLeft, "SIDEOFCANVAS")
                            OoAction.SetData(MoLeftCanvasAdvanced, "UCNDIAGRAMCANVASADVANCED")
                            LeResult = MoLeftCanvasAdvanced.Execute(OoAction)
                            If LeResult = GeActionResult.kkOk Then
                                OoAction.SetData(GeSideOfCanvas.kkRight, "SIDEOFCANVAS")
                                OoAction.SetData(MoRightCanvasAdvanced, "UCNDIAGRAMCANVASADVANCED")
                                LeResult = MoRightCanvasAdvanced.Execute(OoAction)
                            End If
                    End Select
                Case GeAction.kkCloseTab
                    Select Case MeTypeOfTab
                        Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                            'closing of a tab
                            LeResult = ucnDiagramCanvasAdvanced.Execute(OoAction)
                        Case GeTypeOfTab.kkVersionComparisonTab
                            'close left version
                            LeResult = ucnDiagramCanvasAdvanced(GeSideOfCanvas.kkLeft).Execute(OoAction)
                            If LeResult = GeActionResult.kkOk Then
                                'close right version
                                LeResult = ucnDiagramCanvasAdvanced(GeSideOfCanvas.kkRight).Execute(OoAction)
                            End If

                            'close tab
                            If LeResult = GeActionResult.kkOk Then MoTabControl.RemoveTab(Me)
                    End Select
                Case GeAction.kkaModSolutionNewSolution
                    'creating new aMod solution
                    LeResult = ucnDiagramCanvasAdvanced.Execute(OoAction)
                Case GeAction.kkaModSolutionOpenFile
                    'opening aMod solution
                    LeResult = ucnDiagramCanvasAdvanced.Execute(OoAction)
                Case GeAction.kkaModOpenVersion
                    'opening version of aMod in new tab
                    Dim LeSideOfCanvas As GeSideOfCanvas = OoAction.GetData("SIDEOFCANVASADVANCEDFOROPENVERSION", GeSideOfCanvas.kkNone)
                    LeResult = ucnDiagramCanvasAdvanced(LeSideOfCanvas).Execute(OoAction)
                Case GeAction.kkaModTryToOpenUCDofModule
                    'opening use case diagram of module
                    Select Case MeTypeOfTab
                        Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                            LeResult = ucnDiagramCanvasAdvanced.Execute(OoAction)
                        Case GeTypeOfTab.kkVersionComparisonTab
                            LeResult = ucnDiagramCanvasAdvanced(GeSideOfCanvas.kkLeft).Execute(OoAction)
                    End Select
                Case GeAction.kkaModOpenUCDofModule
                    'opening use case diagram of module in tab
                    LeResult = ucnDiagramCanvasAdvanced.Execute(OoAction)
            End Select
            '---------------------------------------------
            'ACTION AFTER ACTION
            '---------------------------------------------
            Select Case OoAction.Action

            End Select
            '---------------------------------------------
            Return LeResult
            '---------------------------------------------

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try

    End Function
    '#######################################

End Class

